/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javafiles;

import java.io.File;
import java.io.IOException;

/**
 *
 * @author human
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
//        File[] listRoots = File.listRoots();
//
//        for (File root : listRoots) {
//            System.out.printf("%s (%s)\n", root.getAbsolutePath(), root.getName());
//
//            searchFiles(root);
//        }
        
        searchFiles(new File("./").getCanonicalFile());
    }

    private static void searchFiles(File rootFile) {
        System.out.printf("%s (%s)\n", rootFile.getAbsolutePath(), rootFile.getName());
        System.out.println("- - - - - - - -");
        
        long children_count = listChildren(0, "  ", rootFile);
        
        System.out.println("- - - - - - - -");
        System.out.printf("Children count: %d\n", children_count);
    }

    private static long listChildren(int level, String sep, File root) {
        File[] children = root.listFiles();

        long count = 0;
        
        if (children != null) {
            count = children.length;
            for (File child : children) {
                for (int i = 0; i < level; i++) {
                    System.out.print(sep);
                }

                System.out.printf("%s%s%s\n",
                        child.isDirectory() ? "- " : "  ",
                        child.getName(),
                        child.isFile() ? String.format(" [ %d bytes ]", child.length()) : "");
                
                if (child.isDirectory()) {
                    count += listChildren(level + 1, sep, child);
                } else {
                }
            }
        }
        
        return count;
    }
}
